<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/template/general.xhtml">

	<ui:define name="title">Home page</ui:define>

	<ui:define name="navigation">
		<h:form id="nav">
			<p:tabMenu activeIndex="0">
				<p:menuitem value="Home" action="home" icon="ui-icon-home" />
				<p:menuitem value="Generate report" action="generate"
					icon="ui-icon-pencil" />
				<p:menuitem value="Report templates" action="template"
					icon="ui-icon-document" />
			</p:tabMenu>
		</h:form>
	</ui:define>

	<ui:define name="content">

		<h:form id="form" update="auto">

			<p:dialog id="projectDialog" header="Select project"
				widgetVar="selectProjectName" dynamic="true">

				<p:dataTable autoUpdate="true" id="projectTable" var="projectEntity"
					value="#{dashboardBean.newProjects}" paginator="true" rows="5"
					paginatorTemplate="{PageLinks}"
					selection="#{dashboardBean.selectedNewProject}"
					selectionMode="single" rowKey="#{projectEntity.id}">

					<p:ajax event="rowSelect" update=":form"
						listener="#{dashboardBean.addDashboardElement}"
						oncomplete="selectProjectName.hide()" />

					<p:column sortBy="#{projectEntity.projectName}"
						id="projectNameColumn" filterBy="#{projectEntity.projectName}"
						headerText="Name" filterMatchMode="contains">
						<h:outputText value="#{projectEntity.projectName}" />
					</p:column>
					<p:column headerText="Comment">
						<h:outputText value="#{projectEntity.comments}" />
					</p:column>


				</p:dataTable>



			</p:dialog>

			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<div style="text-align: right">
				<p:commandButton id="addDashboard" update="projectDialog"
					actionListener="#{dashboardBean.getNewProjectList}"
					oncomplete="selectProjectName.show();" value="Add dashboard" />
			</div>
			<p:dataGrid var="dashboardEntity" value="#{dashboardBean.dashboards}"
				paginator="true" columns="2" rows="8"
				paginatorTemplate="{CurrentPageReport}  {PageLinks}">

				<p:panel header="#{dashboardEntity.projectName}"
					style="text-align:center">
					<h:panelGrid columns="2">
						<h:outputText value="Overall count:" />
						<h:outputText value="#{dashboardEntity.overallCount}" />
						<h:outputText value="Executed count:" />
						<h:outputText value="#{dashboardEntity.executedCount}" />
						<h:outputText value="Last update:" />
						<h:outputText value="#{dashboardEntity.lastUpdate}">
							<f:convertDateTime pattern="d/M/yyyy" />
						</h:outputText>

						<p:pieChart value="#{dashboardEntity.pieChartData}"
							legendPosition="s" title="Tests this week:"
							style="width:400px;height:300px" />

						<p:commandButton value="Remove" update=":form">
							<f:setPropertyActionListener value="#{dashboardEntity}"
								target="#{dashboardBean.selectedForDeleteDashboard}" />

						</p:commandButton>




					</h:panelGrid>
				</p:panel>

			</p:dataGrid>
			<div id="dashboardRefresh" style="text-align: right">
				<p:commandButton update=":form"
					actionListener="#{dashboardBean.updateDashboard}" value="Refresh" />
			</div>
			<f:metadata>
				<f:event type="preRenderView" listener="#{dashboardBean.onPageLoad}" />
			</f:metadata>
		</h:form>
	</ui:define>

</ui:composition>